<?php
require_once 'PHPUnit/Framework.php';
require_once 'TVB/PWORKS/util/CommonUtil.class.php';

class ProgrammeAddActionTest extends PHPUnit_Framework_TestCase
{
	protected function setUp()
	{
		$this->url = "http://pdes.tvb.com/programme_step1.html?act=add&type=programme&step=2&ut=true";
	}

	protected function tearDown()
	{
		$this->url = NULL;
	}

    public function testSuccess()
    {
		$success_data = array(
            'title'             => 'ut_title_zh',
            'path'              => 'TestPath' . time(),
            'cpl_id'            => 'CplId' . time(),
            'cpl_company_code'  => 'TVB',
            'effective_date'    => date('Y-m-d'),
			'pt' => 1
		);

		$ret = CommonUtil::curl_test($this->url,$success_data);
		$real_data = json_decode($ret);

		$err_num = count($real_data);
		if( $err_num == 0 ){
            echo "\n" . '========ProgrammeAddActionTest pass!===================' . "\n";
		}

		$this->assertEquals($err_num, 0); 	
	}

    public function testPathFailed()
    {
		$failed_data = array(
            'path'              => 'donald_path',
            'title'             => 'title_cn',
            'cpl_id'            => 'CplId' . time(),
            'cpl_company_code'  => 'TVB',
            'effective_date'    => date('Y-m-d'),
		);

		$ret = CommonUtil::curl_test($this->url, $failed_data);
		$real_data = json_decode($ret);
		$err_num = count($real_data);
		if( $err_num > 0 ){
            echo '========ProgrammeAddActionTest path failed!===========' . "\n";
            var_export($real_data);
            echo "\n";
		}

		$this->assertEquals($err_num , 0); 	
	}

    public function testTitleFailed()
    {
		$failed_data = array(
            'path'              => 'donald_path',
            'title'             => NULL,
            'cpl_id'            => 'CplId' . time(),
            'cpl_company_code'  => 'TVB',
            'title_en'          => NULL,
            'effective_date'    => date('Y-m-d'),
		);

		$ret = CommonUtil::curl_test($this->url, $failed_data);
		$real_data = json_decode($ret);
		$err_num = count($real_data);
		if( $err_num > 0 ){
            echo '========ProgrammeAddActionTest title failed!===========' . "\n";
            var_export($real_data);
            echo "\n";
		}

		$this->assertEquals($err_num , 0); 	
	}

    public function testCplIdFailed()
    {
		$failed_data = array(
            'path'              => 'TestPathl' . time(),
            'title'             => 'title_cn',
            'title_en'          => NULL,
            'cpl_id'            => '111',
            'cpl_company_code'  => 'TVB',
            'effective_date'    => date('Y-m-d'),
		);

		$ret = CommonUtil::curl_test($this->url, $failed_data);
		$real_data = json_decode($ret);
		$err_num = count($real_data);
		if( $err_num > 0 ){
            echo '========ProgrammeAddActionTest cpl_id failed!===========' . "\n";
            var_export($real_data);
            echo "\n";
		}

		$this->assertEquals($err_num , 0); 	
	}
}

//$suite = new PHPUnit_Framework_TestSuite('ProgrammeAddActionTest');
//$object = $suite->run();
?>
